package day4.HomeWork;

public class Duration {
    /*
    Duration 类：
        1. 定义3个整型属性：hours、minutes、seconds
        2. 定义三参构造器，实现对hours、minutes、seconds进行初始化
        3. 定义一参构造器，实现对hours、minutes、seconds进行初始化，参数为总
        的seconds，例如将x秒，转为a小时b分钟c秒，3661秒，就是1小时1分钟1秒
        4 .定义每个属性对应的get方法，实现获取属性值
    */
    private int hours;
    private int minutes;
    private int seconds;

    //无参构造
    public Duration() {
    }

    //三参构造
    public Duration(int hours, int minutes, int seconds) {
        this.hours = hours;
        this.minutes = minutes;
        this.seconds = seconds;
    }
    //单参构造,例如将x秒，转为a小时b分钟c秒，3661秒，就是1小时1分钟1秒

    public Duration(int seconds) {
        this.hours = seconds/3600;
        this.minutes = seconds%3600/60;
        this.seconds = seconds%3600%60;
    }
    //定义每个属性对应的get方法，实现获取属性值

    public int getHours() {
        return hours;
    }

    public int getMinutes() {
        return minutes;
    }

    public int getSeconds() {
        return seconds;
    }
    //获得总秒数
    public int getTotalSeconds(){
        int total = this.hours*3600+this.minutes*60+this.seconds;
        return total;
    }

    @Override
    public String toString() {
        return this.hours+":"+
                this.minutes+":"+
                this.seconds;
    }
}
